package mythreadpool.a01threadpool1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyThreadPoolDemo {
    public static void main(String[] args) {
        /*
         static ExecutorService newCachedThreadPool()   创建一个默认的线程池
         static newFixedThreadPool(int nThreads)	    创建一个指定最多线程数量的线

         Executors --- 可以帮助我们创建线程池对象
         ExecutorService --- 可以帮助我们控制线程池
         */

        //1,创建一个默认的线程池对象.池子中默认是空的.默认最多可以容纳int类型的最大值.
//        ExecutorService pool1 = Executors.newCachedThreadPool();
        ExecutorService pool1 = Executors.newFixedThreadPool(2);

        //2、提交任务
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());

        //3、销毁线程池
        pool1.shutdown();

    }
}
